//
//  SettingPasswardMViewController.m
//  shuiyun
//
//  Created by 马田成 on 2017/9/8.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "SettingPasswardMViewController.h"
#import "SettingNameHeadViewController.h"

@interface SettingPasswardMViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *passwordTF;

@end

@implementation SettingPasswardMViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.passwordTF.delegate = self;
    
    // Do any additional setup after loading the view from its nib.
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    
    NSCharacterSet *cs;
    
    if (textField == _passwordTF ) {
        
        cs = [[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"] invertedSet];
        NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
        BOOL basicTest = [string isEqualToString:filtered];
        if(!basicTest)  {
            return NO;
        }
        
        if (string.length == 0) return YES;
        
        NSInteger existedLength = textField.text.length;
        NSInteger selectedLength = range.length;
        NSInteger replaceLength = string.length;
        
        if (existedLength - selectedLength + replaceLength > 16) {
            return NO;
        }
    }
    
    return YES;
}


- (IBAction)nextBtnClick:(UIButton *)sender {
    
    SettingNameHeadViewController *vc = [[SettingNameHeadViewController alloc] init];
    
    vc.phoneID = self.phoneID;
    vc.code = self.code;
    vc.password =_passwordTF.text;
    vc.phone = self.phone;

    
    [self presentViewController:vc animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
